package uoc.biblioteca.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import uoc.biblioteca.mappings.dao.ProveedorHome;
import uoc.biblioteca.mappings.object.ProveedorVo;
import uoc.biblioteca.mappings.object.UserVo;
import uoc.biblioteca.struts.form.GestionProveedorForm;


public class GestionProveedorListAction extends BaseAction {
    
   
	private static final Log log = LogFactory.getLog(MisSolicitudsListAction.class);
	
	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) {
    
		
		GestionProveedorForm  gestionProveedorForm = (GestionProveedorForm ) form;
		
		try{
			
			 //Comprobar si la session esta guardada
			UserVo userLogin = obtenerUserSession(request);
			if(userLogin==null){
				request.getSession().setAttribute("ERROR","\n" +NO_USER_SESSION);
				return mapping.findForward("errorNotUser");
			}
			
			ProveedorHome proveedorHome = new ProveedorHome();
			gestionProveedorForm.setProveedores(proveedorHome.getAllProveedores());
			
			return mapping.findForward("gestioProveedorList");
		}
		catch (Exception e) {
			e.printStackTrace();
			log.error("Error: ", e);
			request.getSession().setAttribute("ERROR","\n" +e.toString()  );
			return mapping.findForward("error");
		}
			
	}
}